<?php
$section = 1;
include("includes/secure.php");
include_once("../includes/config.php");
include_once("../includes/class/user.class.php");
require_once("../includes/class/fileManagement.class.php");

$user = new User(); 
$file = new fileManagement();

		
if(isset($_POST['add']) && $_POST['add'] == 1)
{
	$data->name 		= mysql_real_escape_string($_POST['name']);
	$data->dependencia 	= mysql_real_escape_string($_POST['dependencia']);
	$data->email    	= mysql_real_escape_string($_POST['email']);
	$data->phone	    = mysql_real_escape_string($_POST['phone']);
	$data->login 		= mysql_real_escape_string($_POST['login']);
	$data->password 	= md5($data->login.mysql_real_escape_string($_POST['password']).$data->login);		
	$data->type 		= mysql_real_escape_string($_POST['type']);		
	
	if(isset($_FILES['archivo']))
	{
		for($i=0;$i<sizeof($_FILES['archivo']['tmp_name']);$i++)
		{
			if(is_uploaded_file($_FILES['archivo']['tmp_name'][$i]))
			{
				$documento = $file->subirArchivo($_FILES['archivo']['tmp_name'][$i],$_FILES['archivo']['name'][$i],'file_upload/documentos/');								 
				$data->original 	= $_FILES['archivo']['name'][$i];
				$data->renam        = $documento;						
			} 		
		}
	}
	
	if($user->addUser($data))
	{	
		echo "<script>alert('Usuario agregado exitosamente')</script>";	
		echo "<script>window.location.href='list_user.php'</script>";		
				
	}
	else
	{
		echo "<script>alert('El usuario no se pudo agregar')</script>";	
		echo "<script>window.location.href='list_user.php'</script>";
		
	}
	
}else
	{			
		
		$user_types[0] = 'Administrador';
		$user_types[1] = 'Dependencia';
			
	}

?>
